home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Menús / ContextMenuDemo / ContextMenuDemo.cs next >
Encoding:
Text File  |  2002-06-21  |  1.5 KB  |  51 lines

  1. //----------------------------------------------
  2. // ContextMenuDemo.cs ⌐ 2001 by Charles Petzold
  3. //----------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class ContextMenuDemo: Form
  9. {
  10.      MenuItem miColor;
  11.  
  12.      public static void Main()
  13.      {
  14.           Application.Run(new ContextMenuDemo());
  15.      }
  16.      public ContextMenuDemo()
  17.      {
  18.           Text = "Demo de men· contextual";
  19.  
  20.           EventHandler eh = new EventHandler(MenuColorOnClick);
  21.  
  22.           MenuItem[] ami = { new MenuItem("Negro",    eh),
  23.                              new MenuItem("Azul",     eh),
  24.                              new MenuItem("Verde",    eh),
  25.                              new MenuItem("Celeste",  eh),
  26.                              new MenuItem("Rojo",     eh),
  27.                              new MenuItem("Magenta",  eh),
  28.                              new MenuItem("Amarillo", eh),
  29.                              new MenuItem("Blanco",   eh) };
  30.  
  31.           foreach (MenuItem mi in ami)
  32.                mi.RadioCheck = true;
  33.  
  34.           SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  35.  
  36.           miColor = ami[3];
  37.           miColor.Checked = true;
  38.           BackColor = Color.FromName(miColor.Text);
  39.  
  40.           ContextMenu = new ContextMenu(ami);
  41.      }
  42.      void MenuColorOnClick(object obj, EventArgs ea)
  43.      {
  44.           miColor.Checked = false;
  45.           miColor = (MenuItem) obj;
  46.           miColor.Checked = true;
  47.  
  48.           BackColor = Color.FromName(miColor.Text);
  49.      }
  50. }
  51.